<template>
    <el-card class="myMessage">
        <el-page-header @back="goBack" content="报考记录" style="margin-bottom: 20px"></el-page-header>
        <el-card style="margin-bottom: 20px" v-if="recordList.length > 0" v-for="item in recordList" :key="item.id">
            <el-descriptions border :title="item.course.name">
                <el-descriptions-item label="用户名">{{item.user}}</el-descriptions-item>
                <el-descriptions-item label="机构代码">{{item.org_code}}</el-descriptions-item>
                <el-descriptions-item label="考试地点">{{item.exam_city}}</el-descriptions-item>
                <el-descriptions-item label="考试时间">{{dateTimeFilter(item)}}</el-descriptions-item>
                <el-descriptions-item label="成绩">{{item.score}}</el-descriptions-item>
            </el-descriptions>
        </el-card>
        <div v-if="recordList.length == 0">
            <el-empty description="暂无记录"></el-empty>
        </div>
    </el-card>
</template>

<script>
    import {exam_record, examDate} from "../../../request/api";

    export default {
        name: "index",
        data() {
            return {
                recordList: [],
                allTime:[]
            }
        },
        methods: {
            goBack() {
                this.$router.push('/user/myExam')
            },
            getExam_record() {
                exam_record().then(res => {
                    this.recordList = res.result;
                    console.log(res.result);
                })
            },
            getAllTime(){
                examDate().then(res => {
                    this.allTime = res
                })
            },
            dateTimeFilter(item) {
                for (let obj of this.allTime){
                    if(obj.course == item.course.name && obj.exam_city == item.exam_city && obj.exam_date == item.exam_date.split(' ')[0]){
                        return obj.time_detail
                    }
                }
                return item;
            },
        },
        created() {
            this.getExam_record();
            this.getAllTime();
        }
    }
</script>

<style scoped>
    .myMessage {
        width: 1200px;
        margin: 0 auto;
        margin-top: 10px;
    }
</style>
